﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace WuDada.Core.Post.Domain
{
    [Serializable]
    [DataContract]
    public class PostVO : BasePost, IPageTagObject
    {
        #region Constructor

        public PostVO()
        {
            Flag = 1;
            SortNo = 0;
            CloseDate = DateTime.MaxValue.AddDays(-1);
        }

        #endregion

        #region Property

        /// <summary>
        /// Pkey
        /// </summary>
        [DataMember]
        public virtual int PostId { get; set; }

        /// <summary>
        /// 屬於的Node
        /// </summary>
        [DataMember]
        public virtual NodeVO Node { get; set; }

        /// <summary>
        /// 上層的Post
        /// </summary>
        [DataMember]
        public virtual PostVO ParentPost { get; set; }

        /// <summary>
        /// 圖檔
        /// </summary>
        [DataMember]
        public virtual string PicFileName { get; set; }

        /// <summary>
        /// 圖檔2
        /// </summary>
        [DataMember]
        public virtual string PicFileName2 { get; set; }

        ///// <summary>
        ///// 圖檔英文
        ///// </summary>
        //[DataMember]
        //public virtual string PicFileNameENG { get; set; }

        /// <summary>
        /// 文件
        /// </summary>
        [DataMember]
        public virtual string DocFileName { get; set; }

        //[DataMember]
        //public virtual string StoreName { get; set; }

        //[DataMember]
        //public virtual string Phone { get; set; }

        //[DataMember]
        //public virtual string Fax { get; set; }

        //[DataMember]
        //public virtual string GoogleMap { get; set; }

        [DataMember]
        public virtual int SortNo { get; set; }

        /// <summary>
        /// 是否上架
        /// </summary>
        [DataMember]
        public virtual int Flag { get; set; }

        /// <summary>
        /// 上架日/競標期間起
        /// </summary>
        [DataMember]
        public virtual DateTime? ShowDate { get; set; }

        /// <summary>
        /// 下架日/競標期間迄
        /// </summary>
        [DataMember]
        public virtual DateTime? CloseDate { get; set; }

        /// <summary>
        /// 0.站內/個別案件 1.連結/套裝主體 
        /// </summary>
        [DataMember]
        public virtual int Type { get; set; }

        /// <summary>
        /// 連結網址
        /// </summary>
        [DataMember]
        public virtual string LinkUrl { get; set; }

        ///// <summary>
        ///// 內容2(右邊)
        ///// </summary>
        //[DataMember]
        //public virtual string HtmlContent2 { get; set; }

        ///// <summary>
        ///// 內容2英文(右邊)
        ///// </summary>
        //[DataMember]
        //public virtual string HtmlContent2ENG { get; set; }

        /// <summary>
        /// PageTitle
        /// </summary>
        [DataMember]
        public virtual string PageTitle { get; set; }

        /// <summary>
        /// KeyWord
        /// </summary>
        [DataMember]
        public virtual string PageKeyWord { get; set; }

        /// <summary>
        /// Description
        /// </summary>
        [DataMember]
        public virtual string PageDescription { get; set; }

        /// <summary>
        /// 是否為推薦的
        /// </summary>
        [DataMember]
        public virtual bool IsRecommend { get; set; }

        /// <summary>
        /// 價格/出價
        /// </summary>
        [DataMember]
        public virtual double Price { get; set; }

        /// <summary>
        /// 起標價
        /// </summary>
        [DataMember]
        public virtual double StartPrice { get; set; }

        /// <summary>
        /// 是否為暫存
        /// </summary>
        [DataMember]
        public virtual bool IsTemp { get; set; }

        /// <summary>
        /// 自定欄位1/地段
        /// </summary>
        [DataMember]
        public virtual string CustomField1 { get; set; }

        /// <summary>
        /// 自定欄位2/看板數
        /// </summary>
        [DataMember]
        public virtual string CustomField2 { get; set; }

        /// <summary>
        /// 自定欄位3/店家(空白的話如果是專案就帶下面的個別名稱)
        /// </summary>
        [DataMember]
        public virtual string CustomField3 { get; set; }

        /// <summary>
        /// 建立的會員(出租者)
        /// </summary>
        [DataMember]
        public virtual string CreateMember { get; set; }

        /// <summary>
        /// 得標者
        /// </summary>
        [DataMember]
        public virtual string Winner { get; set; }

        /// <summary>
        /// 案件編號
        /// </summary>
        [DataMember]
        public virtual string CaseNo { get; set; }

        /// <summary>
        /// 縣市
        /// </summary>
        [DataMember]
        public virtual string City { get; set; }

        /// <summary>
        /// 地區
        /// </summary>
        [DataMember]
        public virtual string Area { get; set; }

        /// <summary>
        /// 路/街地址
        /// </summary>
        [DataMember]
        public virtual string Road { get; set; }

        [DataMember]
        public virtual string Lat { get; set; }

        [DataMember]
        public virtual string Lng { get; set; }

        [DataMember]
        public virtual string Address
        {
            get
            {
                return City + Area + Road;
            }
        }

        /// <summary>
        /// 收藏數
        /// </summary>
        [DataMember]
        public virtual int Collection { get; set; }

        /// <summary>
        /// 瀏覽數
        /// </summary>
        [DataMember]
        public virtual int Viewer { get; set; }

        /// <summary>
        /// 活動期間起
        /// </summary>
        [DataMember]
        public virtual DateTime? ActDateStart { get; set; }

        /// <summary>
        /// 活動期間迄
        /// </summary>
        [DataMember]
        public virtual DateTime? ActDateEnd { get; set; }

        /// <summary>
        /// 自定欄位4/聯絡人
        /// </summary>
        [DataMember]
        public virtual string CustomField4 { get; set; }

        /// <summary>
        /// 自定欄位5/聯絡電話
        /// </summary>
        [DataMember]
        public virtual string CustomField5 { get; set; }

        /// <summary>
        /// 自定欄位6/手機
        /// </summary>
        [DataMember]
        public virtual string CustomField6 { get; set; }

        /// <summary>
        /// 自定欄位7/E-mail
        /// </summary>
        [DataMember]
        public virtual string CustomField7 { get; set; }

        /// <summary>
        /// 自定欄位8/統編
        /// </summary>
        [DataMember]
        public virtual string CustomField8 { get; set; }

        /// <summary>
        /// 自定欄位9/房屋自有或承租
        /// </summary>
        [DataMember]
        public virtual string CustomField9 { get; set; }

        /// <summary>
        /// 備註
        /// </summary>
        [DataMember]
        public virtual string Note { get; set; }

        #endregion

        /// <summary>
        /// 取文字_上下架
        /// </summary>
        [DataMember]
        public virtual string GetStr_Flag
        {
            get
            {
                string result = "";

                if (Flag == 0)
                {
                    result = "否";
                }
                else if (Flag == 1)
                {
                    result = "是";
                }

                return result;
            }
        }

        /// <summary>
        /// 取文字_名稱+上下架
        /// </summary>
        [DataMember]
        public virtual string GetStr_Name_And_Flag
        {
            get
            {
                string result = Title;

                if (Flag == 0 || !(DateTime.Today >= ShowDate && DateTime.Today <= CloseDate))
                {
                    result += "(下架)";
                }
                //else if (Flag == 1)
                //{
                //    result = "是";
                //}

                return result;
            }
        }

        /// <summary>
        /// 取拍賣狀態文字
        /// </summary>
        [DataMember]
        public virtual string GetStr_BidStatus
        {
            get
            {
                string result = "無";

                try
                {
                    if (Flag == 1 && !string.IsNullOrEmpty(Winner) && CloseDate.HasValue && DateTime.Now >= CloseDate.Value.AddDays(1))
                    {
                        result = "已結標";
                    }
                    else if (Flag == 1 && ShowDate.HasValue && DateTime.Now >= ShowDate.Value && CloseDate.HasValue && DateTime.Now < CloseDate.Value.AddDays(1))
                    {
                        result = "競標中";
                    }
                    else if (Flag == 1 && string.IsNullOrEmpty(Winner) && CloseDate.HasValue && DateTime.Now >= CloseDate.Value.AddDays(1))
                    {
                        result = "流標";
                    }
                    else if (Flag == 0 && !string.IsNullOrEmpty(CreateMember))
                    {
                        result = "審查中";
                    }
                    else if (Flag == 1 && ShowDate.HasValue && DateTime.Now < ShowDate)
                    {
                        result = "未到開標日期";
                    }
                }
                catch (Exception e)
                {
                }

                return result;
            }
        }

        /// <summary>
        /// 取目前競標價
        /// </summary>
        [DataMember]
        public virtual string GetStr_BidPrice
        {
            get
            {
                string result = String.Format("{0:0,0}", Price);

                if (Price <= 0)
                {
                    result = String.Format("{0:0,0}", StartPrice);
                }

                return result;
            }
        }
    }
}
